﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;

namespace Noris.Tools.TraceVisualiser.Components
{
    internal class HotTextBox : TextBox
    {
        public HotTextBox()
        {
            this.Enter += new EventHandler(HotTextBox_Enter);
            this.Leave += new EventHandler(HotTextBox_Leave);
            this.MouseEnter += new EventHandler(HotTextBox_MouseEnter);
            this.MouseLeave += new EventHandler(HotTextBox_MouseLeave);
        }
        void HotTextBox_Enter(object sender, EventArgs e)
        {
            this._HasFocus = true;
            this.SetActive();
        }
        void HotTextBox_Leave(object sender, EventArgs e)
        {
            this._HasFocus = false;
            this.SetInactive();
        }
        void HotTextBox_MouseEnter(object sender, EventArgs e)
        {
            this._HasMouse = true;
            this.SetActive();
        }
        void HotTextBox_MouseLeave(object sender, EventArgs e)
        {
            this._HasMouse = false;
            this.SetInactive();
        }
        private void SetActive()
        {
            this._ShowHelp(true);
        }
        private void SetInactive()
        {
            this._ShowHelp(false);
        }
        private void _ShowHelp(bool show)
        {
            if (this.HelpControl != null && !String.IsNullOrEmpty(this.HelpText))
            {
                if (show)
                    this.HelpControl.Text = this.HelpText;
                else if (!this.LeaveTextOnExit)
                    this.HelpControl.Text = "";
                this.HelpControl.BackColor = System.Drawing.SystemColors.Info;
            }
        }
        [Category("HotTextBox")]
        [Description("Objekt, do jehož property Text se bude promítat hodnota this.HelpText")]
        public Control HelpControl { get; set; }
        [Category("HotTextBox")]
        [Description("Text, který se zobrazí v objektu this.HelpControl v době aktivity tohoto buttonu")]
        [Bindable(true)]
        public string HelpText { get; set; }
        [Category("HotTextBox")]
        [Description("Ponechávat text (this.HelpText) zobrazený v objektu this.HelpControl i po odchodu z this. Default = false.")]
        public bool LeaveTextOnExit { get; set; }
        private bool _StillActive;
        private bool _HasMouse;
        private bool _HasFocus;
    }
}
